﻿/******************************************************************
 *Company: http://www.xiaomutech.com/
 *fileName : qserialshell.h --- QSerialShell
 *Auth       : Niyh  (QQ:393320854)
 *Create    : 2021-11-12
 *Description   :
 *Histroy:
 *<Auth>    <Date>        <Ver>        <Content>
 *         2021/11/12/11/12
 *******************************************************************/
#ifndef QSERIALSHELL_H
#define QSERIALSHELL_H

#include <QTextEdit>
#include <QSerialPort>

class QSerialShell : public QTextEdit
{
    Q_OBJECT
public:
    explicit QSerialShell(QWidget *parent = nullptr);
    ~QSerialShell();

    bool open(const QString &com, quint32 baudrate = 115200);

signals:

private slots:
    void slotReadSerial();

private:
    void sendCommand(const QString &cmd);
    void sendCommand(uchar *data, int len);

private:
    QSerialPort *m_serialport;

    int insertedChars;
    int cursorPosition;
    QString command;

    QString processPath;
    QTextCursor cursor;

    QColor fontColor;
    QStringList commandHistory;
    QStringList commands;
    int commandHistoryPosition;
protected:
    void keyPressEvent(QKeyEvent *e);
};

#endif // QSERIALSHELL_H
